package cn.lg.soar.system.monitor.client;

import cn.lg.soar.common.util.BeanCopier;
import cn.lg.soar.core.annotations.ApiClient;
import cn.lg.soar.system.api.constant.ModuleConst;
import cn.lg.soar.system.api.model.RefreshTokenDTO;
import cn.lg.soar.system.api.service.IRefreshTokenApi;
import cn.lg.soar.system.monitor.entity.RefreshToken;
import cn.lg.soar.system.monitor.service.IRefreshTokenService;
import eu.bitwalker.useragentutils.DeviceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author luguoxiang
 * @date 2022/1/3
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ApiIgnore
@ApiClient("boot")
@RestController
@RequestMapping(ModuleConst.CLIENT_PATH + "/refreshToken")
public class RefreshTokenApiClient implements IRefreshTokenApi {

    @Autowired
    private IRefreshTokenService service;

    private final static BeanCopier<RefreshToken, RefreshTokenDTO> ENTITY_TO_DTO = BeanCopier.create(RefreshToken.class, RefreshTokenDTO.class);

    @GetMapping("getById")
    @Override
    public RefreshTokenDTO getById(@RequestParam String id) {
        RefreshToken entity = service.getById(id);
        return ENTITY_TO_DTO.convertNullable(entity);
    }

    @GetMapping("verify")
    @Override
    public RefreshTokenDTO verify(@RequestParam String refreshToken) {
        RefreshToken entity = service.verify(refreshToken);
        return ENTITY_TO_DTO.convertNullable(entity);
    }

    @GetMapping("idsByUserId")
    @Override
    public List<String> idsByUserId(@RequestParam List<Long> userIds, @RequestParam DeviceType deviceType) {
        return service.idsByUserId(userIds, deviceType);
    }

    @GetMapping("idsByUserIdAndActive")
    @Override
    public List<String> idsByUserIdAndActive(@RequestParam List<Long> userIds, @RequestParam DeviceType deviceType) {
        return service.idsByUserIdAndActive(userIds, deviceType);
    }

}
